<!-- 购物车内容 -->
<style>
.table-bordered th{text-align:center;}
</style>

<div class="flowBox">
	<h6 style="display:none;">
		<span>{$lang.goods_list}</span>
	</h6>
	<form id="formCart" name="formCart" method="post" action="flow.php">
		<table class="table-bordered" width="99%" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
			<tr style="height:50px;">
				<th bgcolor="#ffffff" width="400px">{$lang.goods_name}</th>
				<if condition="$show_goods_attribute eq 1">
					<th bgcolor="#ffffff">{$lang.goods_attr}</th>
				</if>
				<if condition="$show_marketprice">
					<th bgcolor="#ffffff">{$lang.market_prices}</th>
				</if>
				<th bgcolor="#ffffff">{$lang.shop_prices}</th>
				<th bgcolor="#ffffff">{$lang.number}</th>
				<th bgcolor="#ffffff">{$lang.subtotal}</th>
				<th bgcolor="#ffffff">{$lang.handle}</th>
			</tr>
			<volist name="goods_list" id="goods">
				<tr class="datas" id="tr_{$goods.goods_id}" goods_id="{$goods.goods_id}">
					<td bgcolor="#ffffff" align="center">
						<if condition="$goods['goods_id'] gt 0 and $goods['extension_code'] neq 'package_buy'">
							<if condition="$show_goods_thumb eq 1">
								<a href="goods.php?id={$goods.goods_id}" target="_blank" class="f6">{$goods.goods_name}</a>
							<elseif condition="$show_goods_thumb eq 2"/>
								<a href="goods.php?id={$goods.goods_id}" target="_blank">
									<img src="__UPLOAD__/images/{$goods.goods_thumb}" border="0" title="{$goods.goods_name}" />
								</a>
							<else/>
								<div class="cart-item clearfix" style="padding:20px;">
									<a href="goods.php?id={$goods.goods_id}" target="_blank">
										<img src="__UPLOAD__/images/{$goods.goods_thumb}" border="0" width="102px" height="102px" title="{$goods.goods_name}" />
									</a>
									<a href="goods.php?id={$goods.goods_id}" target="_blank" class="f6 goods_name">
										{$goods.goods_name}
									</a>
								</div>								
							</if>
							<if condition="$goods['parent_id'] gt 0">
								<span style="color:#FF0000">（{$lang.accessories}）</span>
							</if>
							<if condition="$goods['is_gift'] gt 0">
								<span style="color:#FF0000">（{$lang.largess}）</span>
							</if>
						<elseif condition="$goods['goods_id'] gt 0 and $goods['extension_code'] eq 'package_buy'"/>
							<a href="javascript:void(0)" onclick="setSuitShow({$goods.goods_id})" class="f6">{$goods.goods_name}<span style="color:#FF0000;">（{$lang.remark_package}）</span></a>
							<div id="suit_{$goods.goods_id}" style="display:none">
							<volist name="goods['package_goods_list']" id="package_goods_list">
								<a href="goods.php?id={$package_goods_list.goods_id}" target="_blank" class="f6">{$package_goods_list.goods_name}</a><br />
							</volist>
							</div>
						<else/>
							{$goods.goods_name}
						</if>
					</td>
					<if condition="$show_goods_attribute eq 1">
						<td bgcolor="#ffffff" align="center">
							<if condition="$goods['goods_attr']">
								{$goods.goods_attr}
							<else/>
								---
							</if>
						</td>
					</if>
					<!-- 显示市场价 -->
					<if condition="$show_marketprice">
						<td align="right" bgcolor="#ffffff" align="center">{$goods.market_price}</td>
					</if>
					<!-- 本店售价 -->
					<td align="right" bgcolor="#ffffff" align="center" style="text-align:center;">{$goods.goods_price}</td>
					<td align="right" bgcolor="#ffffff" align="center">
						<!-- 普通商品可修改数量 -->
						<if condition="($goods['goods_id'] gt 0) and ($goods['is_gift'] eq 0) and ($goods['parent_id'] eq 0)">							
							<div class="add_minus_wrap" style="">
								<span class="minus">-</span>
									<input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" rec_id="{$goods.rec_id}" shop_prices="{$goods.goods_price}"  value="{$goods.goods_number}" size="4" class="inputBg" style="text-align:center "  onKeyUp="showdiv(this)"/>
								<span class="add" goods_id="{$goods.goods_id}">+</span>
							</div>							
						<else/>
							{$goods.goods_number}
						</if>
					</td>
					<td align="right" bgcolor="#ffffff" align="center" style="text-align:center;">{$goods.subtotal}</td>
					<td align="center" bgcolor="#ffffff">
						<a rec_id="{$goods.rec_id}" class="f6 del_btn qs-del-btn" title="{$lang.drop}" alt="{$lang.drop}"></a>
						<!-- 如果登录了，可以加入收藏 -->
						<if condition="$Think.session.user_id gt 0 and $goods['extension_code'] neq 'package_buy'">						
							<a style="display:none;" href="javascript:if (confirm('{$lang.drop_goods_confirm}')) location.href='flow.php?step=drop_to_collect&amp;id={$goods.rec_id}'; " class="f6">
								{$lang.drop_to_collect}
							</a>
						</if>
					</td>
				</tr>
			</volist>
		</table>
		<table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" style="display:none;">
			<tr>
				<td bgcolor="#ffffff">
					<if condition="$discount gt 0">
						{$your_discount}<br />
					</if>
					{$shopping_money}
					<if condition="$show_marketprice">
						，{$market_price_desc}
					</if>
				</td>
			  <td align="right" bgcolor="#ffffff">
					<input type="button" value="{$lang.clear_cart}" class="bnt_blue_1" onclick="location.href='__URL__/clear'" />
					<input name="submit" type="submit" class="bnt_blue_1" value="{$lang.update_cart}" />
			  </td>
			</tr>
		</table>
		<input type="hidden" name="step" value="update_cart" />
	</form>	
	<!--结算按钮-->	
	<div class="store_cart">
		<!--应付金额-->
		<div class="cart_price_total">
			<p>
				<span class="cart_price_total_text">
					商品总额
				</span>
				<span class="cart_price_total_number">
					¥&nbsp;
					{$total.goods_price}
				</span>
			</p>
			<p>
				<span class="cart_price_total_text">
					套餐优惠
				</span>
				<span id="package_discount">
					-&nbsp;¥&nbsp;
					<i>
						0.00
					</i>
				</span>
			</p>
		</div>
		<div style="clear:both;"></div>
		<div class="pay_price">
			<span style="display: inline-block; width: 55px; text-align: left;">
				应付
			</span>
			<span id="total_pay">
				¥&nbsp;{$total.goods_price}
			</span>
		</div>
		<br/>
		<!--应付金额-->
		<div class="space100" style="height:0px;width:100%;"></div>
		<div class="cart_submit">
			<a class="cart_continue_buy" href="{:U('goods/index')}">
				继续购物
			</a>
			<a class="cart_go_to_checkout" href="javascript:void(0);" href_data="__URL__/checkout">
				去结算
			</a>
		</div>
	</div>
	<div class="space30" style="height:30px;width:100%;"></div>
	<!--结算按钮-->
<script>	
	/*添加*/
	$('.datas').find('.add').each(function(){										
		$(this).click(function(){
			var value = parseInt($(this).prev().val());
			var rec_id = $(this).prev().attr('rec_id');			
			value = value + 1;
			$(this).prev().attr('value',value);
			/*ajax修改购买数量*/
			$.ajax({
				url:'__URL__/update_cart',
				type:'post',
				dataType:'json',
				data:{datas:rec_id + "_" + value},
				beforeSend:function(){
					loading	=	layer.load(0,2);			
				},
				success:function(msg){
					layer.close(loading);			
					/*刷新页面*/
					location.reload();
				}
			});	
		});																	
	});
	/*减少*/
	$('.minus').click(function(){
		var value = parseInt($(this).next().val());
		value = value -1;
		var rec_id = $(this).next().attr('rec_id');
		if(value < 1){
			$(this).prev().attr('value',1);
			return;
		}
		$(this).next().attr('value',value);
		/*ajax修改购买数量*/
		$.ajax({
			url:'__URL__/update_cart',
			type:'post',
			dataType:'json',
			data:{datas:rec_id + "_" + value},
			beforeSend:function(){
				loading	=	layer.load(0,2);			
			},
			success:function(msg){
				layer.close(loading);			
				/*刷新页面*/
				location.reload();
			}
		});			
	});
</script>
   <if condition="$Think.session.user_id gt 0">
	   <script type="text/javascript" charset="utf-8">
			function collect_to_flow(goodsId){
				var goods        = new Object();
				var spec_arr     = new Array();
				var fittings_arr = new Array();
				var number       = 1;
				goods.spec     	= spec_arr;
				goods.goods_id 	= goodsId;
				goods.number   	= number;
				goods.parent   	= 0;
				//Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), collect_to_flow_response, 'POST', 'JSON');
			}
			function collect_to_flow_response(result)
			{
			  if (result.error > 0)
			  {
				// 如果需要缺货登记，跳转
				if (result.error == 2)
				{
				  if (confirm(result.message))
				  {
					location.href = 'user.php?act=add_booking&id=' + result.goods_id;
				  }
				}
				else if (result.error == 6)
				{
				  openSpeDiv(result.message, result.goods_id);
				}
				else
				{
				  alert(result.message);
				}
			  }
			  else
			  {
				location.href = 'flow.php';
			  }
			}
		</script>
		<div class="blank"></div>
	</if>

	<if condition="$collection_goods">
		<div class="flowBox" style="display:none;">
			<h6>
				<span>{$lang.label_collection}</span>
			</h6>
			<table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
			<volist name="collection_goods" id="goods">
				<tr>
					<td bgcolor="#ffffff">
						<a href="goods.php?id={$goods.goods_id}" class="f6">{$goods.goods_name}</a>
					</td>
					<td bgcolor="#ffffff" align="center" width="100">
						<a href="javascript:addToCart({$goods.goods_id})" class="f6">{$lang.collect_to_flow}</a>
					</td>
				</tr>
			</volist>
			</table>		
		</div>
	</if>
	<div class="blank5"></div>
</div>


<script>
$(document).ready(function(){
	/*改变删除按钮样式*/
	$('.qs-del-btn').hover(function(){ 
		$(this).addClass('qs-del-hover'); 
	},function(){
		$(this).removeClass('qs-del-hover');
	});
	/*删除商品*/
	$('.qs-del-btn').click(function(){
		if (confirm('{$lang.drop_goods_confirm}')){
			var rec_id	=	$(this).attr("rec_id");
			$.ajax({
				type:"post",
				url:"{:U('flow/drop_goods')}",
				dataType:'json',
				data:{id:rec_id},
				timeout:10000,
				beforeSend:function(){
					$('#loading').QLoading({text:'',status:'open',modal:true});
				},
				success:function(msg){
					if(msg.info == 'ok'){
						$('#loading').QLoading({text:'删除成功',img:'happy',status:'close',modal:true,time:1});
						setTimeout(function(){
							location.reload();
						},1500);
					}
					else{
						$('#loading').QLoading({text:'删除失败',img:'sad',status:'close',modal:true,time:1});
					}
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					//alert(textStatus)
				}
			});	
		}
	});	
	/*提交表单*/
	$('.cart_go_to_checkout').click(function(){
		location.href = "{:U('flow/checkout')}";
	});
});


/*修改购买数量*/
function showdiv(obj){
	/*数量不能为空*/
	if(obj.value == ''){
		layer.msg('购买数量不能为空', 1, function(){
			//obj.value = 1;
		}); return;
	}
	var datas	=	new Array();
	var value 	=	parseInt(obj.value);
	var rec_id 	=	obj.getAttribute('rec_id');		
	var loading	= null;		
	/*数量少于1,强制设为1*/	
	if(value < 1){
		obj.value = 1;
		layer.close(loading);
		value	=	1;
	}
	/*ajax修改购买数量*/
	$.ajax({
		url:'__URL__/update_cart',
		type:'post',
		dataType:'json',
		data:{datas:rec_id + "_" + value},
		beforeSend:function(){
			loading	=	layer.load(0,2);			
		},
		success:function(msg){
			layer.close(loading);			
			/*刷新页面*/
			location.reload()
		}
	});
}


</script>

